package com.shxy.rlzy.mapper;

import com.shxy.rlzy.entity.Role;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author tanhao
 * @since 2021-08-16
 */
public interface RoleMapper extends BaseMapper<Role> {

    /**
     * 根据编码查询角色
     * @param clerk
     * @return
     */
    @Select("SELECT * FROM sys_role WHERE code=#{code}")
    Role getByCode(String clerk);

    @Select("SELECT sr.* FROM sys_role AS sr,sys_user AS su,sys_user_role AS sur WHERE sr.id=sur.role_id AND su.id=sur.user_id AND su.username=#{username}")
    Role getByUsername(String username);

    @Select("SELECT DISTINCT sr.* FROM sys_role AS sr LEFT JOIN sys_user_role AS sur ON sr.id=sur.role_id WHERE sur.user_id=#{userId}")
    Role getByUserId(long userId);

    @Select("SELECT * FROM sys_role WHERE id=#{roleId}")
    Role getById(long roleId);
}
